import { Element } from 'diagram-js/lib/model/Types'
import { ModdleElement } from 'bpmn-moddle'
import editor from '@/store/editor'
import modeler from '@/store/modeler'
import { is, getBusinessObject } from 'bpmn-js/lib/util/ModelUtil'
export function setElementValue(element: Element, value: boolean, key: String) {
    const prefix = editor().getProcessEngine
    const modeling = modeler().getModeling
    // overwrite the legacy `async` property, we will use the more explicit `asyncBefore`
    const businessObject = getBusinessObject(element);
    modeling?.updateModdleProperties(element, businessObject, {
        [`${prefix}:${key}`]: value
    });
}

export function getElementValue(element: Element, keys) {
    const prefix = editor().getProcessEngine
    const businessObject = getBusinessObject(element);
    const elementObjectValue = {};
    keys.forEach(key => {
        elementObjectValue[key] = businessObject.get(`${prefix}:${key}`);
    });
    return elementObjectValue;
}

export function setElementValues(element, obj) {
    const prefix = editor().getProcessEngine
    const modeling = modeler().getModeling
    // overwrite the legacy `async` property, we will use the more explicit `asyncBefore`
    const businessObject = getBusinessObject(element);
    const prefixObj = {};
    Object.keys(obj).forEach(key => {
        prefixObj[`${prefix}:${key}`] = obj[key];
    });
    modeling?.updateModdleProperties(element, businessObject, prefixObj);
}
export function hasElement(element, key) {
    const prefix = editor().getProcessEngine
    return is(element, `${prefix}:${key}`);
}